<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="环保登记编码">
                            <a-input placeholder="请输入环保登记编码"
                                v-model="queryParam.registrationCode"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <a-form-item label="车牌号码">
                            <a-input placeholder="请输入车牌号码" v-model="queryParam.plateNo"></a-input>
                        </a-form-item>
                    </a-col>
                    <template v-if="toggleSearchStatus">
                        <a-col :xl="6" :lg="7" :md="8" :sm="24">
                            <a-form-item label="排放标准">
                                <j-dict-select-tag placeholder="请选择排放标准"
                                    v-model="queryParam.evnType" dictCode="evn_type" />
                            </a-form-item>
                        </a-col>
                        <a-col :xl="6" :lg="7" :md="8" :sm="24">
                            <a-form-item label="燃料类型">
                                <j-dict-select-tag placeholder="请选择燃料类型"
                                    v-model="queryParam.fuelType" dictCode="fuel_type" />
                            </a-form-item>
                        </a-col>
                        <a-col :xl="6" :lg="7" :md="8" :sm="24">
                            <a-form-item label="机械种类">
                                <j-dict-select-tag placeholder="请选择机械种类"
                                    v-model="queryParam.machineryType" dictCode="machinery_type" />
                            </a-form-item>
                        </a-col>
                        <a-col :xl="10" :lg="11" :md="12" :sm="24">
                            <a-form-item label="进厂日期">
                                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间" class="query-group-cust"
                                    v-model="queryParam.entryTime_begin"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间" class="query-group-cust"
                                    v-model="queryParam.entryTime_end"></j-date>
                            </a-form-item>
                        </a-col>
                        <a-col :xl="10" :lg="11" :md="12" :sm="24">
                            <a-form-item label="出厂日期">
                                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择开始时间" class="query-group-cust"
                                    v-model="queryParam.exitTime_begin"></j-date>
                                <span class="query-group-split-cust"></span>
                                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="请选择结束时间" class="query-group-cust"
                                    v-model="queryParam.exitTime_end"></j-date>
                            </a-form-item>
                        </a-col>
                    </template>
                    <a-col :xl="6" :lg="7" :md="8" :sm="24">
                        <span style="float: left;overflow: hidden;"
                            class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery"
                                icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                            <a @click="handleToggleSearch" style="margin-left: 8px">
                                {{ toggleSearchStatus ? '收起' : '展开' }}
                                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                            </a>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <a-button @click="handleAdd" type="primary" icon="plus"
                v-has="'ledger:add'">新增</a-button>
            <a-button type="primary" icon="download"
                @click="handleExportXls('非道路移动机械电子台账')">导出</a-button>
            <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                :action="importExcelUrl" @change="handleImportExcel" v-has="'ledger:import'">
                <a-button type="primary" icon="import">导入</a-button>
            </a-upload>
            <a-dropdown v-if="selectedRowKeys.length > 0" v-has="'ledger:del'">
                <a-menu slot="overlay">
                    <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
                    style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id"
                :columns="columns" :dataSource="dataSource" :pagination="ipagination"
                :loading="loading"
                :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                class="j-table-force-nowrap" @change="handleTableChange">

                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <viewer :options="options" v-else class="viewer" ref="viewer">
                        <img src="../../../assets/yulan.png" :data-source="getImgView(text)"
                            height="25px" alt=""
                            style="max-width: 80px; font-size: 12px; font-style: italic" />
                    </viewer>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small"
                        @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>

                <span slot="action" slot-scope="text, record">
                    <a @click="handleEdit(record)" v-has="'ledger:edit'">编辑</a>

                    <a-divider type="vertical" v-has="'ledger:edit'" />
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                        <a-menu slot="overlay">
                            <a-menu-item>
                                <a @click="handleDetail(record)">详情</a>
                            </a-menu-item>
                            <a-menu-item v-has="'ledger:del'">
                                <a-popconfirm title="确定删除吗?"
                                    @confirm="() => handleDelete(record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </span>

            </a-table>
        </div>

        <no-road-ledger-modal ref="modalForm" @ok="modalFormOk"></no-road-ledger-modal>
    </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import NoRoadLedgerModal from './modules/NoRoadLedgerModal'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import 'viewerjs/dist/viewer.css'

export default {
    name: 'NoRoadLedgerList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        NoRoadLedgerModal
    },
    data() {
        return {
            options: { url: 'data-source' },
            description: '非道路移动机械电子台账管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '环保登记编码',
                    align: "center",
                    dataIndex: 'registrationCode'
                },
                {
                    title: '机械生产日期',
                    align: "center",
                    dataIndex: 'producedTime',
                    customRender: function (text) {
                        return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
                    }
                },
                {
                    title: '车牌号码',
                    align: "center",
                    dataIndex: 'plateNo'
                },
                {
                    title: '排放标准',
                    align: "center",
                    dataIndex: 'evnType_dictText'
                },
                {
                    title: '燃料类型',
                    align: "center",
                    dataIndex: 'fuelType_dictText'
                },
                {
                    title: '机械种类',
                    align: "center",
                    dataIndex: 'machineryType_dictText'
                },
                {
                    title: '机械环保代码/产品识别码（PIN）',
                    align: "center",
                    dataIndex: 'pin'
                },
                {
                    title: '机械型号',
                    align: "center",
                    dataIndex: 'mechanicalModel'
                },
                {
                    title: '发动机型号',
                    align: "center",
                    dataIndex: 'engineModel'
                },
                {
                    title: '发动机生产厂',
                    align: "center",
                    dataIndex: 'engineProducer'
                },
                {
                    title: '发动机编号',
                    align: "center",
                    dataIndex: 'engineNum'
                },
                {
                    title: '整车（机）铭牌',
                    align: "center",
                    dataIndex: 'machineNameplate',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '发动机铭牌',
                    align: "center",
                    dataIndex: 'engineNameplate',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '机械环保信息标签',
                    align: "center",
                    dataIndex: 'machineLabel',
                    scopedSlots: { customRender: 'imgSlot' }
                },
                {
                    title: '所属人（单位）',
                    align: "center",
                    dataIndex: 'vehicleOwner'
                },
                {
                    title: '进厂日期',
                    align: "center",
                    dataIndex: 'entryTime'
                },
                {
                    title: '出厂日期',
                    align: "center",
                    dataIndex: 'exitTime'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: "center",
                    fixed: "right",
                    width: 147,
                    scopedSlots: { customRender: 'action' }
                }
            ],
            url: {
                list: "/noRoadLedger/noRoadLedger/list",
                delete: "/noRoadLedger/noRoadLedger/delete",
                deleteBatch: "/noRoadLedger/noRoadLedger/deleteBatch",
                exportXlsUrl: "/noRoadLedger/noRoadLedger/exportXls",
                importExcelUrl: "noRoadLedger/noRoadLedger/importExcel",

            },
            dictOptions: {},
            superFieldList: [],
        }
    },
    created() {
        this.getSuperFieldList();
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        },
    },
    methods: {
        initDictConfig() {
        },
        getSuperFieldList() {
            let fieldList = [];
            fieldList.push({ type: 'string', value: 'registrationCode', text: '环保登记编码', dictCode: '' })
            fieldList.push({ type: 'date', value: 'producedTime', text: '机械生产日期' })
            fieldList.push({ type: 'string', value: 'plateNo', text: '车牌号码', dictCode: '' })
            fieldList.push({ type: 'string', value: 'evnType', text: '排放标准', dictCode: 'evn_type' })
            fieldList.push({ type: 'string', value: 'fuelType', text: '燃料类型', dictCode: 'fuel_type' })
            fieldList.push({ type: 'string', value: 'machineryType', text: '机械种类', dictCode: 'machinery_type' })
            fieldList.push({ type: 'string', value: 'pin', text: '机械环保代码/产品识别码（PIN）', dictCode: '' })
            fieldList.push({ type: 'string', value: 'mechanicalModel', text: '机械型号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'engineModel', text: '发动机型号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'engineProducer', text: '发动机生产厂', dictCode: '' })
            fieldList.push({ type: 'string', value: 'engineNum', text: '发动机编号', dictCode: '' })
            fieldList.push({ type: 'string', value: 'machineNameplate', text: '整车（机）铭牌', dictCode: '' })
            fieldList.push({ type: 'string', value: 'engineNameplate', text: '发动机铭牌', dictCode: '' })
            fieldList.push({ type: 'string', value: 'machineLabel', text: '机械环保信息标签', dictCode: '' })
            fieldList.push({ type: 'string', value: 'vehicleOwner', text: '所属人（单位）', dictCode: '' })
            fieldList.push({ type: 'datetime', value: 'entryTime', text: '进厂日期' })
            fieldList.push({ type: 'datetime', value: 'exitTime', text: '出厂日期' })
            this.superFieldList = fieldList
        }
    }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>